﻿@model OT.Areas.Admin.Models.Categories
<div class="modal-content">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i></button>
        <h3 id="myModalLabel">Edit Category</h3>
    </div>
    @Html.HiddenFor(model => model.CategoryID, new { id = "HDFID" })
    <div class="modal-body">
        <div id="alert_modal"></div>
        <div class="form-horizontal" role="form">
            <div class="form-group">
                <div class="col-lg-13">
                    <div id="divMsgEdit"></div>
                </div>
            </div>
            <div class="form-group" id="divCategoryName">
                <label class="col-lg-3 control-label">Category Name</label>
                <div class="col-lg-5">
                    @Html.TextBoxFor(model => model.CategoryName, new { @maxlength = "20", @class = "form-control", @placeholder = "Enter Category Name" })
                    @Html.ValidationMessageFor(model => model.CategoryName)
                </div>
            </div>
            <div class="form-group" id="divDescription">
                <label class="col-lg-3 control-label">Description</label>
                <div class="col-lg-5">
                    <textarea rows="3" class="form-control" id="Description" maxlength="50" placeholder="Enter Description">@Model.Description</textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-lg-3 control-label">Select SubCategory</label>
                <div class="col-lg-5">
                    @Html.DropDownListFor(model => model.SubCategoryID, new SelectList(Model.SubCategories, "CategoryID", "CategoryName"), "--Select--", new { @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.SubCategoryID)
                </div>
            </div>
            <div class="form-group">
                <label class="col-lg-3 control-label">Status</label>
                <div class="col-lg-1">
                    @Html.EditorFor(model => model.Status)
                </div>
            </div>
        </div>
    </div>
    <div class="modal-footer">
        <button class="btn btn-default" type="submit" id="btnEdit"><i class="icon-cog"></i>Save</button>
        <button class="btn btn-default" data-dismiss="modal" aria-hidden="true"><i class="icon-off"></i>Cancel</button>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $('#btnEdit').click(function () {
            var CategoryID = $("#HDFID").val();
            var CategoryName = $("#CategoryName").val();
            var Description = $("#Description").val();
            var check = $("#Status").val();
            if ($("#Status").is(':checked')) {
                Status = true;
            }
            else {
                Status = false;
            }
            var SubCategory = $("#SubCategoryID").val();
            if (CategoryName == '') {
                showMsg("divMsgEdit", "Enter All Required Value", "danger");
                (CategoryName == '') ? $('#divCategoryName').addClass('has-error') : $('#divCategoryName').removeClass('has-error');
            }
            else {
                $.ajax({
                    url: "/Admin/Category/Edit?CategoryID=" + CategoryID + "&CategoryName=" + CategoryName + "&Description=" + Description + "&Status=" + Status + "&subcategory=" + SubCategory,
                    type: "POST",
                    success: function (result) {
                        if (result != "NotValid") {
                            $('#modalDiv').modal('hide');
                            showMsg("divMsgIndex", "Successfuly Updated Record !!", "success");
                            loadPage(1, 10, '');
                        }
                        else {
                            showMsg("divMsgEdit", "Failed to Update Record !!", "danger");
                        }
                    },
                    error: function (data) {
                    }
                });
            }
            return false;
        });
    });
</script>
